<?php
/**
 * 同步登录完成后，用来删除session项目的api模块
 *
 * @ingroup API
 * @ingroup Extensions
 */
namespace UCenter;

use ApiBase;

class ApiSynloginFinish extends ApiBase {
	public const SYNLOGIN_SESSIONKEY = 'isekai_uc_synlogin_url';

	public function execute() {
		$sessionManager = \MediaWiki\Session\SessionManager::getGlobalSession();
		$result = $this->getResult();
		if($sessionManager->exists(self::SYNLOGIN_SESSIONKEY)){
			$sessionManager->remove(self::SYNLOGIN_SESSIONKEY);
			$result->addValue(null, 'removed', 'finish');
		}
		$result->addValue(null, 'removed', 'none');
		return true;
	}

	public function getAllowedParams() {
		return [];
	}

	/**
	 * @see ApiBase::getExamplesMessages()
	 * @return array
	 */
	protected function getExamplesMessages() {
		return [
			'action=synloginfinish' => 'apihelp-synloginfinish-example',
		];
	}
}